<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1.通过call判断类型
    //Object.prototype.toString返回对象名
    var toString = Object.prototype.toString
    console.log(toString.call(1));
    console.log(toString.call('2'));
    console.log(toString.call(true));
    console.log(toString.call(undefined));
    console.log(toString.call(NaN));
    console.log(toString.call(new Date()));
    console.log(toString.call(null));
    console.log(toString.call(/^1[356789]%d{9}$/));
    console.log('-------------------------------------------------');
    // 2通过构造器判断类型
    var n = 1
    console.log(n);
    console.log(n.constructor);
    n = '1'
    console.log(n.constructor);
    n = true
    console.log(n.constructor);
    // n = undefined
    // console.log(n.constructor);
    n = NaN
    console.log(n.constructor);
    var n = new Date()
    console.log(n.constructor);
    // n = null
    // console.log(n.constructor);
    n = /^1[356789]%d{9}$/
    console.log(n.constructor);
    console.log('-------------------------------------------------');

    //通过typeof判断类型
    console.log(typeof 1);
    console.log(typeof '2');
    console.log(typeof true);
    console.log(typeof undefined);
    console.log(typeof NaN);
    console.log(typeof new Date());
    console.log(typeof null);
    console.log(typeof /^1[356789]%d{9}$/);

  </script>
</body>

</html>